package com.dk.utils;

import com.dk.entity.dos.UserDo;
import com.dk.entity.dto.UserDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * Description:
 *
 * @author WangDk
 * @date:2021/10/12 10:54
 */
@Mapper
public interface UserConverter  {
    UserConverter INSTANCE = Mappers.getMapper(UserConverter.class);
    @Mappings({
            @Mapping(source = "name", target = "userName"),
            @Mapping(source = "age", target = "userAge"),
            @Mapping(source = "address", target = "userAddress"),
            @Mapping(target = "time",expression = "java(com.dk.utils.DateTransform.strToDate(userDo.time))")
    })

    /**
     *单个转化数据
     *
     */
    UserDto firstToUserDto(UserDo userDo);

    /**
     * 批量处理转换数据
     * @param userDo
     * @return
     */
    List<UserDto> toUserDtoList(List<UserDo> userDo);
}
